package com.rules.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rules.admin.dao.RuleUserRoleDao;
import com.rules.admin.entity.RuleUserRole;
import com.rules.admin.utils.Constant;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import com.rules.admin.service.RuleUserRoleService;



@Service
public class RuleUserRoleServiceImpl extends ServiceImpl<RuleUserRoleDao, RuleUserRole> implements RuleUserRoleService {


   @Override
   public List<RuleUserRole> getListByUserId(Long userId) {
      LambdaQueryWrapper<RuleUserRole> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(RuleUserRole::getUserId,userId);
      return this.list(queryWrapper);
   }

   public RuleUserRole getByUserId(Long userId) {
      LambdaQueryWrapper<RuleUserRole> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(RuleUserRole::getUserId,userId);
      return this.getOne(queryWrapper);


   }

   public List<Long> getAdminUserId() {
      LambdaQueryWrapper<RuleUserRole> queryWrapper = new LambdaQueryWrapper<>();
      queryWrapper.eq(RuleUserRole::getRoleId,Constant.PERMISSION_ADMIN);
      List<RuleUserRole> ruleUserRoles = this.list(queryWrapper);


      List<Long> ids = new ArrayList();
      Iterator iterator = ruleUserRoles.iterator();

      while(iterator.hasNext()) {
         RuleUserRole ruleUserRole = (RuleUserRole)iterator.next();
         ids.add(ruleUserRole.getUserId());
      }

      return ids;
   }
}
